<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:head>

    </h:head>

    <h:body>
        <h:form>
            <p:commandLink value="Cadastrar novo pai, mãe ou responsável" onclick="addHuman.show()"/>
            <f:event type="preRenderComponent" listener="#{humanRegister.initializeHuman()}"/>
        </h:form>
        <p:dialog id="addHumanDialog" position="top" modal="true" widgetVar="addHuman" closable="false" resizable="true" width="1000" height="500">

            <h:form id="addHumanForm">
                <p:messages/>
                <p:tabView id="addHumanView">
                    <p:tab title="Dados Principais">
                        <p:panel styleClass="mainInfoTab">
                            <h:panelGrid columns="2">
                                <h:outputLabel for="humanName" value="Nome*:"/>
                                <p:inputText id="humanName" value="#{humanRegister.human.firstName}"
                                             required="true" requiredMessage="'Nome' é obrigatório"/>
                                <h:outputLabel for="humanLastName" value="Sobrenome*:"/>
                                <p:inputText id="humanLastName" value="#{humanRegister.human.lastName}"
                                             required="true" requiredMessage="'Sobrenome' é obrigatório"/>
                                <h:outputLabel for="humanSex" value="Sexo*:"/>
                                <h:selectOneMenu id="humanSex" value="#{humanRegister.human.sex}">
                                    <f:selectItems value="#{humanRegister.sexList}"/>
                                </h:selectOneMenu>
                                <h:outputLabel for="humanBirthday" value="Nascimento*:"/>
                                <p:inputMask id="humanBirthday" mask="99/99/9999" value="#{humanRegister.human.birthday.time}"
                                             required="true" requiredMessage="'Nascimento' é obrigatório">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </p:inputMask>
                                <h:outputLabel for="humanNacionality" value="Nacionalidade:"/>
                                <h:selectOneMenu id="humanNacionality" value="#{humanRegister.nationalityID}">
                                    <f:selectItems value="#{humanRegister.nationalityList}"/>
                                </h:selectOneMenu>
                                <h:outputLabel for="humanEthnicity" value="Etnia:"/>
                                <h:selectOneMenu id="humanEthnicity" value="#{humanRegister.ethnicityID}">
                                    <f:selectItems value="#{humanRegister.ethnicityList}"/>
                                </h:selectOneMenu>
                                <h:outputLabel for="humanPhone" value="Telefone Fixo:"/>
                                <p:inputMask id="humanPhone" mask="(99)9999-9999" value="#{humanRegister.human.phone}"/>
                                <h:outputLabel for="humanCelphone" value="Celular:"/>
                                <p:inputMask id="humanCelphone" mask="(99)9999-9999" value="#{humanRegister.human.celphone}"/>
                                <h:outputLabel for="humanEmail" value="Email:"/>
                                <p:inputText id="humanEmail" value="#{humanRegister.human.email}"/>
                                <h:outputLabel for="humanLaterality" value="Lateralidade:"/>
                                <h:selectOneMenu id="humanLaterality" value="#{humanRegister.human.laterality}">
                                    <f:selectItems value="#{humanRegister.lateralityList}"/>
                                </h:selectOneMenu>
                                <h:outputLabel for="humanMaritalStatus" value="Estado Civil:"/>
                                <h:selectOneMenu id="humanMaritalStatus" value="#{humanRegister.human.maritalStatus}">
                                    <f:selectItems value="#{humanRegister.maritalStatusList}"/>
                                </h:selectOneMenu>                
                            </h:panelGrid>
                        </p:panel>
                    </p:tab>
                    <p:tab title="Endereço">
                        <p:panel id="address" styleClass="addressPanel">
                            <p:message for="cep"/>
                            <h:outputLabel value="CEP*" for="cep"/>
                            <p:inputMask id="cep" value="#{humanRegister.cep}" mask="99999999" required="true" requiredMessage="'CEP' é obrigatório"/>
                            <h:commandButton value="Buscar">
                                <f:ajax execute="cep" render="address" listener="#{humanRegister.searchCEP()}"/>
                            </h:commandButton>
                            <br/>
                            <h:panelGroup id="zipcode">
                                <h:outputLabel value="Estado*:" for="state"/>
                                <p:inputText id="state" value="#{humanRegister.zipcode.city.state.name}" required="true" readonly="true"/>
                                <br/>
                                <h:outputLabel value="Cidade*:" for="city"/>
                                <p:inputText id="city" value="#{humanRegister.zipcode.city.name}" required="true" readonly="true"/>
                                <br/><br/>
                            </h:panelGroup>
                            <h:panelGroup rendered="#{humanRegister.showAddress}">
                                <h:outputLabel value="Bairro*:" for="neighborhood"/>
                                <p:autoComplete id="neighborhood" value="#{humanRegister.neighborhood}" 
                                                completeMethod="#{humanRegister.neighborhoodComplete}" 
                                                required="true" requiredMessage="'Bairro' é campo obrigatório"
                                                minQueryLength="3"/>
                                <br/>
                                <h:outputLabel value="Logradouro*:" for="street"/>
                                <p:autoComplete id="street" value="#{humanRegister.street}" 
                                                completeMethod="#{humanRegister.streetComplete}" 
                                                required="true" requiredMessage="'Logradouro' é campo obrigatório"
                                                minQueryLength="3"/>
                                <br/><br/>
                                <h:outputLabel value="Número:" for="number"/>
                                <p:inputText id="number" value="#{humanRegister.address.number}"/>
                                <br/>
                                <h:outputLabel value="Complemento" for="complement"/>
                                <p:inputText id="complement" value="#{humanRegister.address.complement}"/>                            
                            </h:panelGroup>
                        </p:panel>
                    </p:tab>    
                    <p:tab title="Dados Específicos">
                        <p:panel>
                            <h:panelGrid columns="2" id="addInfoPanel">
                                <h:selectOneMenu id="addInfoTypes" value="#{humanRegister.addInfoTypeID}">
                                    <f:selectItems value="#{humanRegister.additionalInfoTypeList}"/>
                                    <f:ajax execute="addInfoTypes" render="addInfoPanel" listener="#{humanRegister.loadMask(humanRegister.addInfoTypeID)}"/>
                                </h:selectOneMenu>
                                <p:inputMask mask="#{humanRegister.mask}" value="#{humanRegister.additionalInfo}"/>
                            </h:panelGrid>
                        </p:panel>
                    </p:tab>                 
                </p:tabView>
                <h:commandButton value="Salvar">
                    <f:ajax listener="#{humanRegister.saveHuman()}" render="@form" execute="@form"/>
                </h:commandButton>
                <h:commandButton value="Cancelar" immediate="true" onclick="addHuman.hide()">
                    <f:ajax listener="#{humanRegister.initializeHuman()}" render="@form"/>
                </h:commandButton>
            </h:form>

            <p:dialog modal="true" widgetVar="statusDialog" 
                      draggable="false" closable="false">
                <p:graphicImage value="../../resources/images/ajax/ajaxloader.gif"/>
            </p:dialog>   
        </p:dialog>
    </h:body>
</html>